package com.starry.module.system.core.oauth2.mapper;

import com.starry.core.common.domain.vo.PageVo;
import com.starry.db.core.enums.DBEnableDisableStatusEnum;
import com.starry.db.core.mapper.BaseMapperX;
import com.starry.db.core.query.LambdaQueryWrapperX;
import com.starry.module.system.api.oauth2.domain.qo.Oauth2ThirdClientPageQo;
import com.starry.module.system.core.oauth2.entity.Oauth2ThirdClient;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 第三方客户端-数据库服务层
 *
 * @author xiaoke
 */
@Mapper
public interface Oauth2ThirdClientMapper extends BaseMapperX<Oauth2ThirdClient> {

    /**
     * 分页查询
     *
     * @param pageQo 分页参数
     * @return PageVo<Oauth2ThirdClient>
     */
    default PageVo<Oauth2ThirdClient> selectPage(Oauth2ThirdClientPageQo pageQo) {
        return selectPage(pageQo, new LambdaQueryWrapperX<Oauth2ThirdClient>()
        );
    }

    /**
     * 根据客户端编码查询
     *
     * @param clientCode 客户端编码
     * @return Oauth2ThirdClient
     */
    default Oauth2ThirdClient selectByClientCode(String clientCode) {
        return selectOne(new LambdaQueryWrapperX<Oauth2ThirdClient>()
                .eq(Oauth2ThirdClient::getCode, clientCode)
        );
    }

    default List<Oauth2ThirdClient> selectClientList() {
        return selectList(new LambdaQueryWrapperX<Oauth2ThirdClient>()
                .eq(Oauth2ThirdClient::getStatus, DBEnableDisableStatusEnum.ENABLE.getCode())
        );
    }
}

